package com.springboot.controller;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.springboot.po.User;
import com.springboot.service.UserService;

@RestController
@RequestMapping(path = "/UserController" , method = RequestMethod.POST)
public class UserController {
	@Autowired
	UserService userService;
	
	@RequestMapping("/login")
    public String login(String userId , String password){ //这里是JWT登录成功把token返回给前端
        String token = userService.login(userId , password);
        if(token.equals("用户不存在！")) {
        	return "fail";
        }
        return "success, token: " + token;
    }

	@RequestMapping("/getUserById")
	public int getUserById(String userId) throws Exception{
		return userService.getUserById(userId);
	}
	
	@RequestMapping("/register")
	public String register(User user)throws Exception {
		return userService.saveUser(user);
	}
	
	@RequestMapping("/getUserByIdByPass")
	public User getUserByIdByPass(User user) throws Exception{
		return userService.getUserByIdByPass(user);
	}
	
	@RequestMapping("/findSerect")
	public User findSerect(User user) throws Exception{
		return userService.findSerect(user);
	}
	
	@RequestMapping("/getPoints")
	public BigDecimal getPoints(String userId) throws Exception{
		//查询积分
		return userService.getPoints(userId);
	}
	
	@RequestMapping("/getMaxPoints")
	public BigDecimal getMaxPoints(String userId) throws Exception{
		//查询积分
		return userService.getMaxPoints(userId);
	}

	@RequestMapping("/getMemLevel")
	public int getMemLevel(String userId)throws Exception {
		//查询等级
		return userService.getMemLevel(userId);
	}
	
	@RequestMapping("/spendPoints")
	public int spendPoints(String userId , BigDecimal price)throws Exception {
		//消费积分
		return userService.spendPoints(userId , price);
	}

}
